﻿using System;
using System.Collections.Generic;
using System.Linq.Expressions;

namespace DotNetRepository
{
    public interface IEntityRepository<TEntity> where TEntity : class, IEntity
    {
        TEntity GetByID(Guid id);
        TEntity GetCachedByID(Guid id);

        /// <summary>
        /// Returns true if changes have been made to an object that have not yet been saved.
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        bool IsDirty(TEntity entity);

        void Save(TEntity obj);
        void Save(TEntity obj, object sender);
        void Revert(TEntity entity);

        void Delete(TEntity obj);
        void Delete(TEntity obj, object sender);
        bool IsCached(Guid id);
        bool Contains(TEntity entity);
        bool Contains(Guid id);
        bool Any(Expression<Func<TEntity, bool>> predicate);
        List<Guid> GetIDs(Expression<Func<TEntity, bool>> predicate);

        List<TEntity> Where(Expression<Func<TEntity, bool>> predicate);
        List<TEntity> GetByIDs(IEnumerable<Guid> idList);
        TEntity FirstOrDefault(Expression<Func<TEntity, bool>> filter);
        TEntity LastOrDefault(Expression<Func<TEntity, bool>> filter);

        /// <summary>
        /// Get a readonly view of a table for querying data on the database.
        /// </summary>
        /// <param name="context">Represents a DataContext.  Queries deriving from more than one table must
        /// use the same context.</param>
        /// <returns></returns>
        IEnumerable<TEntity> GetTable(ref object context);
        
    }
}
